#include <iostream>
#include <vector>
#include <string>
#include <cassert>
using namespace std;

bool word(string s, vector<string> d) {
    int n = s.length();
    vector<bool> dp(n + 1, 0);
    dp[0] = 1;
    
    for (int i = 1; i <= n; i++) {
        for(int j = 0; j < d.size(); j++) {
            string w = d[j];
            int len = w.length();
            if (i >= len && dp[i - len]) {
                bool m = 1;
                for (int k = 0; k < len; k++) {
                    if (s[i - len + k] != w[k]) {
                        m = 0;
                        break;
                    }
                }
                if(m) {
                    dp[i] = 1;
                    break;
		}
            }
        }
    }
    return dp[n];
}

int main() {
    assert(word("ilike", {"i", "like", "gfg"}) == true);
    assert(word("ilikegfg", {"i", "like", "man", "india", "gfg"}) == true);
    assert(word("ilikemangoes", {"i", "like", "gfg"}) == false);
    return 0;
}
